package com.dana.gomoku.interceptor;

import com.dana.gomoku.constant.Constants;
import com.dana.gomoku.mapper.UserMapper;
import com.dana.gomoku.model.User;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
@Component
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        User user = (User) session.getAttribute(Constants.USER_SESSION_KEY);
        if (user==null){
            response.setStatus(401);
            return false;
        }
        return true;
    }
}
